package org.example.zuoye032;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class MyService {

    private final RestTemplate restTemplate;

    @Autowired
    public MyService(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    public String callExternalService() {
        String url = "http://example.com/api/resource";
        // 执行GET请求
        String result = restTemplate.getForObject(url, String.class);
        return result;
    }
}